package top.kaoshanji.p1ch02c;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.invoke.MethodType;

/**
 * 代码清单 p1ch02c-04：对MethodType中的返回值和参数类型进行修改的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/2 16:55
 */
public class MethodTypeExample04 {

    private static final Logger logger = LogManager.getLogger(MethodTypeExample04.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch02c-04：对MethodType中的返回值和参数类型进行修改的示例...");

        MethodType mt = MethodType.methodType(String.class, int.class, int.class);
        System.out.println(mt);

        mt = mt.appendParameterTypes(float.class);
        System.out.println(mt);

        mt = mt.insertParameterTypes(1, double.class, long.class);
        System.out.println(mt);

        mt = mt.dropParameterTypes(2, 3);
        System.out.println(mt);

        mt = mt.changeParameterType(2, String.class);
        System.out.println(mt);

        mt = mt.changeReturnType(void.class);
        System.out.println(mt);

    }

}
